/****************************************************************************
**                                                                         **
**                           PSSDK HNQueue module                          **
**            Copyright (c) 1997 - 2006 microOLAP Technologies LTD,        **
**                       Khalturin A.P., Naumov D.A.                       **
**                               Header File                               **
**                                                                         **
****************************************************************************/

//---------------------------------------------------------------------------
#ifndef __HN_PSSDK_QUEUE_H__
#define __HN_PSSDK_QUEUE_H__ 
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Class CHNQueue
//---------------------------------------------------------------------------
class CHNQueue
{
private:
    HANDLE hQue;

public:
    //###########################################################################
    //    Create & Destroy
    //###########################################################################

    //---------------------------------------------------------------------------
    // v2.2 - QueCreate - Creates the HNQueue object.
    CHNQueue() { hQue = QueCreate(); }

    //---------------------------------------------------------------------------
    // v2.2 - QueDestroy - Destroys the HNQueue object.
    ~CHNQueue() { QueDestroy(hQue); }

public:
    //###########################################################################
    //    Additionals methods
    //###########################################################################
    BOOL     IsValid() { return (BOOL)(hQue != NULL); }
    HANDLE   Get_Handle() { return hQue; }
    operator HANDLE() { return hQue; }


public:
    //###########################################################################
    //    Methods of redirect
    //###########################################################################

    //---------------------------------------------------------------------------
    // v2.2 - QueGetMaxPacketSize - Returns the queue packet maximum size.
    DWORD Get_MaxPacketSize() 
    { return QueGetMaxPacketSize(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueSetMaxPacketSize - Sets the queue packet maximum size.
    DWORD Set_MaxPacketSize(DWORD MaxPacketSize) 
    { return QueSetMaxPacketSize(hQue,MaxPacketSize); }

    //---------------------------------------------------------------------------
    // v2.2 - QueGetItemsCount - Returns an overall quantity of queue elements.
    DWORD Get_ItemsCount() 
    { return QueGetItemsCount(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueSetItemsCount - Sets an overall quantity of queue elements.
    DWORD Set_ItemsCount(DWORD ItemsCount) 
    { return QueSetItemsCount(hQue,ItemsCount); }

    //---------------------------------------------------------------------------
    // v2.2 - QueGetAllocatedSize - Returns total size of the memory pool used by queue.
    SIZE_T Get_AllocatedSize() 
    { return QueGetAllocatedSize(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueGetFreeCount - Returns total amount of the queue items with Free status.
    DWORD Get_FreeCount() 
    { return QueGetFreeCount(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueGetFullCount - Returns total amount of the queue items with Full status.
    DWORD Get_FullCount() 
    { return QueGetFullCount(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueAllocItems - Allocates memory for queue items and creates queue synchronization objects.
    DWORD AllocItems() 
    { return QueAllocItems(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueFreeItems - Releases queue resources.
    DWORD FreeItems() 
    { return QueFreeItems(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueGetFreeItem - Returns an element with Free status from the queue.
    HANDLE Get_FreeItem(DWORD Milliseconds) 
    { return QueGetFreeItem(hQue,Milliseconds); }

    //---------------------------------------------------------------------------
    // v2.2 - QueReturnFreeItem - Returns an element with Free status back to the queue.
    VOID Return_FreeItem(HANDLE hPkt) 
    { QueReturnFreeItem(hQue,hPkt); }

    //---------------------------------------------------------------------------
    // v2.2 - QueGetFullItem - Returns an element with Full status from the queue.
    HANDLE Get_FullItem(DWORD Milliseconds) 
    { return QueGetFullItem(hQue,Milliseconds); }

    //---------------------------------------------------------------------------
    // v2.2 - QueReturnFullItem - Returns an element with Full status back to the queue.
    VOID Return_FullItem(HANDLE hPkt) 
    { QueReturnFullItem(hQue,hPkt); }

    //---------------------------------------------------------------------------
    // v2.2 - QueUnblockWaitFree - Turns out all application threads awaiting for Free elements from awaiting status.
    BOOL UnblockWaitFree() 
    { return QueUnblockWaitFree(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueUnblockWaitFull - Turns out all application threads awaiting for Full elements from awaiting status.
    BOOL UnblockWaitFull() 
    { return QueUnblockWaitFull(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueStart - Creates and starts internal queue thread.
    DWORD Start() 
    { return QueStart(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueStop - Stops internal queue thread.
    DWORD Stop() 
    { return QueStop(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueIsStarted - Shows the status of the internal thread.
    BOOL IsStarted() 
    { return QueIsStarted(hQue); }

    //---------------------------------------------------------------------------
    // v2.2 - QueSetOnThreadBegin - Sets the OnThreadBegin event.
    FARPROC Set_OnThreadBegin(FARPROC pfOnThreadBegin, DWORD_PTR Param) 
    { return QueSetOnThreadBegin(hQue,pfOnThreadBegin,Param); }

    //---------------------------------------------------------------------------
    // v2.2 - QueSetOnThreadEnd - Sets the OnThreadEnd event.
    FARPROC Set_OnThreadEnd(FARPROC pfOnThreadEnd, DWORD_PTR Param) 
    { return QueSetOnThreadEnd(hQue,pfOnThreadEnd,Param); }

    //---------------------------------------------------------------------------
    // v2.2 - QueSetOnDeleteItems - Sets the OnDelete event.
    FARPROC Set_OnDeleteItems(FARPROC pfOnDeleteItems, DWORD_PTR Param) 
    { return QueSetOnDeleteItems(hQue,pfOnDeleteItems,Param); }

    //---------------------------------------------------------------------------
    // v2.2 - QueSetOnPacketRecv - Sets the OnPacketReceive event.
    FARPROC Set_OnPacketRecv(FARPROC pfOnPacketRecv, DWORD_PTR Param) 
    { return QueSetOnPacketRecv(hQue,pfOnPacketRecv,Param); }
};

//---------------------------------------------------------------------------
#endif // __HN_PSSDK_QUEUE_H__
//---------------------------------------------------------------------------
